package wangwenjun.phase2.concurrencypattern.activeobject.dynamicproxy;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import wangwenjun.phase2.concurrencypattern.activeobject.dynamicproxy.framework.ActiveObjectServiceFactory;
import wangwenjun.phase2.concurrencypattern.future.Future;

/**
 * @author ChangLiang
 * @date 2020/6/18
 */
@Slf4j
public class AppTest {

    @Test
    @DisplayName("test")
    public void test() throws InterruptedException {
        OrderService orderService = ActiveObjectServiceFactory.createActiveObject(new OrderServiceImpl());
        // OrderServiceImpl@35a50a4c
        System.out.println(orderService.toString());

        // class com.sun.proxy.$Proxy9 此时就是动态代理类了
        System.out.println(orderService.getClass().toString());

        // 调用动态代理类的任何方法都会调用invoke方法
        orderService.createOrder("changliang-account",123456);
        log.info("return immediately");
        Thread.currentThread().join();
    }

    @Test
    @DisplayName("test")
    public void test2() throws InterruptedException {
        OrderService orderService = ActiveObjectServiceFactory.createActiveObject(new OrderServiceImpl());

        // 调用动态代理类的任何方法都会调用invoke方法
        Future<String> orderDetails = orderService.findOrderDetails(123456);
        log.info("return immediately");
        Thread.currentThread().join();
    }

    @Test
    @DisplayName("test")
    public void test3() throws InterruptedException {
        OrderService orderService = ActiveObjectServiceFactory.createActiveObject(new OrderServiceImpl());

        // 调用动态代理类的任何方法都会调用invoke方法
        Future<String> orderDetails = orderService.findOrderDetails(123456);
        String s = orderDetails.get();
        log.info("get result:{}",s);
        Thread.currentThread().join();
    }
}
